import { Component, OnInit } from '@angular/core';
import { Stepcounter } from '@ionic-native/stepcounter/ngx';

@Component({
  selector: 'app-sensors',
  templateUrl: './sensors.page.html',
  styleUrls: ['./sensors.page.scss'],
})
export class SensorsPage implements OnInit {
  count = 0;
   starting = 0;
  private timer;
  constructor(private stepcounter: Stepcounter) { }

  ngOnInit() {
    // this.sensors.enableSensor(TYPE_SENSOR.STEP_COUNTER);//计步传感器
   
 let   startingOffset = 0;
this.stepcounter.start(startingOffset).then(onSuccess =>  this.starting = startingOffset, onFailure => console.log('stepcounter-start error', onFailure));
    this.timer = setInterval(() => {
      this.stepcounter.getStepCount().then(counts =>this.count = counts , onFailure => console.log('stepcounter-history error', onFailure));
    }, 1500);
  }
  clear(){
    this.count = 0;
  }
  read(){
    this.stepcounter.getTodayStepCount().then(counts =>this.count = counts , onFailure => console.log('stepcounter-history error', onFailure));
  }
  ngOnDestroy(){
    this.stepcounter.stop().then(onSuccess => console.log('stepcounter-start success', onSuccess), onFailure => console.log('stepcounter-start error', onFailure));
  } 
}
